<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('邮件新增')"/>
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">接收人电子邮件</label>
                    <div class="layui-input-block">
                        <input type="text" name="receiversEmail" autocomplete="off" placeholder="xxx@cc.com" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮件标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" autocomplete="off"  class="layui-input" placeholder="邮件标题">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">内容</label>
                    <div class="layui-input-block">
                        <textarea id="content" name="content" style="display: none;"></textarea>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="email-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery','layedit'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = rootPath+"/EmailController";
	
        let FILE_PATH = rootPath+"/oss";
        let BucketName='[[${BucketName}]]';
        let layedite=layui.layedit;
        layedite.set({
	       	  uploadImage: {
	       	    url: FILE_PATH+'/createObjectLayedit/'+BucketName //接口url
	       	    ,type: 'post' //默认post
	       	  }
		});
        let layeditIndex=layedite.build('content'); //建立编辑器

        //保存
        form.on('submit(email-save)', function (data) {
            $.ajax({
                url: MODULE_PATH+'/add',
                data: JSON.stringify({receiversEmail:data.field['receiversEmail'],title:data.field['receiversEmail'],content:layedite.getContent(layeditIndex)}),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("email-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>